<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
</html>
<script>
  var str = "abcabacbacbacbacabcd"; //创建字符串
  var obj = {}; //创建空对象
  //对象的键名不能重复,键值可以重复
  for (i = 0; i < str.length; i++) {
    //选取对象点方法会隐式转换成字符串类型
    var key = str[i];
    if (typeof obj[key] == "undefined") {
      obj[key] = 1;
    } else {
      obj[key]++;
    }
  }
  console.log(obj);
</script>
